<template>
  <!-- 新增设计主管页面 -->
  <div v-loading="loading">
    <el-form  :inline="true" ref="ruleFormRef" :model="form" :rules="rules" label-width="120px">
     <el-form-item label="订单类别:" prop="orderType">
       <el-select disabled v-model="form.orderType" placeholder="请选择是否有售后">
         <el-option label="自然订单" value="0" />
         <el-option label="渠道订单" value="1" />
       </el-select>
     </el-form-item>
     <el-form-item label="订单状态:" prop="orderStatus">
       <el-select disabled v-model="form.orderStatus"  placeholder="请选择订单状态">
         <el-option  v-for="item in orderstatus" :key="item.id" :label="item.dictLabel" :value="item.dictValue" />
       </el-select>
     </el-form-item>
     <el-form-item label="客户姓名:" prop="clientName">
       <el-input v-model="form.clientName" />
     </el-form-item>
     <el-form-item label="选择量尺时间:" prop="measuringTime">
        <el-date-picker
          v-model="form.measuringTime"
          type="date"
          placeholder="请选择量尺时间"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
     <el-form-item label="客户电话:" prop="phone">
       <el-input type="number" v-model.number="form.phone" />
     </el-form-item>
 
     <el-form-item label="地址:" prop="address">
       <el-input v-model="form.address" />
     </el-form-item>
 
     <el-form-item label="合作方:" prop="partner">
     <el-input
       v-model="form.partner"
       placeholder="输入合作方的名称"
     >
       <template  #prepend>
         <el-select v-model="form.partner" placeholder="选择合作方" style="width: 115px">
           <el-option v-for="(item,index) in PartnerOfCompany.data" :key="index" :label="item" :value="item" />
         </el-select>
       </template>
     </el-input>
     </el-form-item>
    
     <el-form-item label="设计师:" prop="designer">
       <el-select   v-model="form.designer" placeholder="请选择设计师">
         <el-option v-for="item in designer.data" :key="item.empCode" :label="item.empName" :value="item.empCode" />
       </el-select>
     </el-form-item>
 
     <el-form-item label="订单管理员:" prop="orderManager">
       <el-select  v-model="form.orderManager" placeholder="请选择订单管理员">
         <el-option v-for="item in manger.data" :key="item.empCode" :label="item.empName" :value="item.empCode" />
       </el-select>
     </el-form-item>


<!--      全量设计师-->
      <el-form-item label="全案设计师姓名:" prop="fullDesignerName">
        <el-input v-model="form.fullDesignerName" />
      </el-form-item>
      <el-form-item label="全案设计师电话:" prop="fullDesignerPhone">
        <el-input v-model="form.fullDesignerPhone" />
      </el-form-item>


     <el-form-item label="备注:">
       <el-input v-model="form.comment" type="textarea" style="width: 400px" />
     </el-form-item>
   </el-form>
   <div class="_button">
     <el-button type="primary" size="large" @click="onSubmit(ruleFormRef)">保存</el-button>
   </div>
  </div>
  
 </template>
 
 <script lang="ts" setup>
 import { ref, reactive,defineEmits  } from 'vue'
 import {tbOrderSave, tbgetDesigner, tbgetOrderManager,tbgetPartnerOfCompany} from '/@/api/tb/tbOrder'
 import { ElMessage } from 'element-plus'
 import {GetWhole} from "../Util_Function/getOrderWhole"
 import { tbDictList } from '/@/api/tb/tbDictType'
 // import {useUserStore} from "../../../store/modules/user"
 const data = ref([])
 const orderstatus = ref([])
 const ruleFormRef = ref<any>()
 const loading=ref(true)
 const manger =ref([])
 
 const emit = defineEmits(['editForm'])
 const form = reactive({
   orderType:'',//订单类别
   clientName: '', // 客户姓名
   phone: '', // 联系电话
   address: '', // 地址
   partner: '', // 合作方
   designer: '', // 设计师
   orderStatus: '', // 订单状态
   comment: '' ,// 备注
   orderManager:'',
   measuringTime: '', //量尺时间
 })
 // const userstore=useUserStore().userInfo
 // console.log(userstore);
 
 const designer=ref([])
 const PartnerOfCompany=ref([])
 const getOffices = async () => {
   loading.value=true
   for (let key in form) {
         form[key]=''
   }
   form.orderType='1'
   form.orderStatus="4"
   const status = await tbDictList({ dict: 'the_order_status' })
   orderstatus.value = status.data
   designer.value=await tbgetDesigner()
   manger.value=await tbgetOrderManager()
   PartnerOfCompany.value=  await tbgetPartnerOfCompany()
   console.log(PartnerOfCompany.value);
   
   data.value = await GetWhole();
   if(data.value.length&&orderstatus.value.length){
     loading.value=false
   }
 }
 getOffices()
 
 
 
 const onSubmit = async (formEl) => {
   if (!formEl) return
   await formEl.validate( async(valid) => {
     if (valid) {
      const regMobile = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
      if (regMobile.test(form.phone)) {
       const res= await tbOrderSave(form)
   if(res.result){
     for (let key in form) {
         form[key]=''
   }
   form.orderType='1'
   form.orderStatus="4"
     emit('editForm') 
     ElMessage({
     message:res.message,
     type: 'success',
   })
   }else{
     ElMessage.error(res.message)
   } }else{
        ElMessage.error('手机格式有误')
      } }
   })
 }
 const rules = reactive({
   orderType: [{ required: true,message: '请输入客户姓名',trigger: 'blur'}],
   clientName: [{ required: true,message: '请输入客户姓名',trigger: 'blur'}],
  phone: [{ required: true,message: '请输入联系电话',trigger: 'blur'}],
   address: [{ required: true,message: '请输入地址',trigger: 'blur'}],
   partner: [{ required: true,message: '请输入合作方',trigger: 'blur'}],
   designer: [{ required: true,message: '请选择设计师',trigger: 'change'}],
   orderManager: [{ required: true,message: '请选择订单管理员',trigger: 'change'}],
   orderStatus: [{ required: true,message: '请选择订单状态',trigger: 'change'}],
   measuringTime: [{ required: true, message: '请选择量尺时间', trigger: 'change' }],
   fullDesignerName: [{ required: true, message: '请输入全案设计师名字', trigger: 'change' }],
   fullDesignerPhone: [{ required: true, message: '请输入全案设计师电话', trigger: 'change' }],
 })
 
 </script>
 <style lang="less" scoped>
 ._button {
   width: 100%;
   display: flex;
   justify-content: flex-end;
   padding-right: 50px;
 }
 .el-input {
   width: 300px;
 }
 </style>
